<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Profile extends Access_Controller {
	function __construct()
	{
		parent::__construct();

		$this->load->model('crud_model');
		$this->load->model('profile_model');
	}

	function index()
	{
		$page["_contents"] = "administrator/user/v_user_profile";
		
		$id = $this->session->userdata('user_id');

		$data['row'] = $this->profile_model->getProfile($id)->row();

		$this->template->load("administrator/template/main_template",$page, $data);
	}

	function update_profile()
	{
		$id = $this->session->userdata('user_id');
		$data["fullname"] = $this->input->post("fullname");
		$data["email"] = $this->input->post("email");
		$data["phone"] = $this->input->post("phone");
		
		$this->crud_model->update('users', $id, $data, 'id');

		$this->session->set_flashdata('update-notif', 'yes');
		redirect('administrator/profile');
	}

	function change_account()
	{
		$id = $this->session->userdata('user_id');
		$old_password = $this->input->post('old-password');

		$row = $this->profile_model->getProfile($id)->row();

		if(md5($old_password) == $row->password)
		{
			$data['password'] = md5($this->input->post('new-password'));
			$this->crud_model->update('users', $id, $data, 'id');

			$this->session->set_flashdata('update-notif', 'yes');
			redirect('administrator/profile');
		}
		else
		{
			$this->session->set_flashdata('danger-notif', 'yes');
			redirect('administrator/profile');
		}
	}
}

/* End of file profile.php */
/* Location: ./application/controllers/profile.php */